Email::Handle - A Objective Email Handler
use Email::Handle; my $email = Email::Handle->new('root@example.com'); print $email->is_valid ? 'yes' : 'no'; print $email->obfuscate; print $email->anonymize; print $email; $email->send(From => 'foo@example.com');
This module is also convenient for using on the DB application with Template and Class::DBI / DBIx::Class.
# setup the table that has column of email with this module my $loader = Class::DBI::Loader->new( ... namespace => 'MyApp' ); $loader->find_class('user')->has_a(email => 'Email::Handle'); # then output records with TT2 my $tmpl = Template->new; $tmpl->process( 'sample.tt', { users => $loader->find_class('user')->retrieve_all } ); # You can write the template with some methods of this module like this [% WHILE (user IN users) %] [% user.email.obfuscate IF user.email.is_valid %] [% END %]
This module allows you to handle an email address as a object.
Returns Email::Handle object. It has three forms of construction.
my $email = Email::Handle->new('root@example.com');
or
my $email = Email::Handle->new( user => 'root', host => 'example.com' );
my $email = Email::Handle->new; $email->user('root'); $email->host('example.com');
Set/get an email address. A passed string will be splited and setted as user and host internally.
Returns a Email::Handle object to a plain string. Email::Handle objects are also converted to plain strings automatically by overloading. This means that objects can be used as plain strings in most Perl constructs.
my $email = Email::Handle->new('root@example.com'); print $email->as_string; # 'root@example.com' print $email; # 'root@example.com'
Set/get a user name for an email address.
$email->user; # 'root' $email->user('foo'); # changing the user from 'root' to 'foo'
Set/get a host name for an email address.
$email->host; # 'examplle.com' $email->host('cpan.org'); # changing the host from 'example.com' to 'cpan.org'
Validates whether an address is well-formed with Email::Valid/Email::Valid::Loose and returns false if the address is not valid. This method takes some options as arguments.
$email->is_valid; # validating with Email::Valid $email->is_valid(loose => 1); # validating with Email::Valid::Loose # Any other arguments will be passed to the validator. $email->is_valid(-mxcheck => 1);
Returns obfuscated HTML email addresses which is hard to be scraped. It requires "HTML::Email::Obfuscate ".
$email->obfuscate;
This code generates obfuscated strings like this:
roo<span>t</span><!-- @ -->@hat<span>e</span>na<B>.</b>ne<B>.</b><span>j</span>p
Arguments will be passed to the constructor of the HTML::Email::Obfuscate.
$email->obfuscate(javascript => 1); $email->obfuscate(lite => 1);
Returns an anonymized email address like this:
$email->anonymize; # 'root@e...' $email->anonymize('***'); # 'root@e***'
Returns MIME::Lite message object for sending mail to the address. Arguments will be passed to the constructor of MIME::Lite;
$email->mime( From => 'me@myhost.com', Subject => 'Hello' )->send;
If you want to use any other MIME classes like MIME::Lite::TT rather than MIME::Lite, override package variable $Email::Handle::MIME_CLASS
$Email::Handle::MIME_CLASS
$Email::Handle::MIME_CLASS = 'MIME::Lite::TT'; my $msg = $email->mime(...)
A shortcut method for sending mail with MIME::Lite.
$email->send(From => 'me@myhost.com', Subject => 'Hello');
Naoya Ito, <naoya at bloghackers.net>
<naoya at bloghackers.net>
Please report any bugs or feature requests to bug-email-handle at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Email-Handle. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-email-handle at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Email::Handle
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Email-Handle
CPAN Ratings
http://cpanratings.perl.org/d/Email-Handle
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Email-Handle
Search CPAN
http://search.cpan.org/dist/Email-Handle
Copyright 2006 Naoya Ito, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
L<> starts or ends with whitespace
To install Email::Handle, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Email::Handle
CPAN shell
perl -MCPAN -e shell install Email::Handle
For more information on module installation, please visit the detailed CPAN module installation guide.